package com.ocean.service.library.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocean.dao.library.CategoryDao;
import com.ocean.dao.library.LibraryDao;
import com.ocean.entity.library.Announcement;
import com.ocean.entity.library.Category;
import com.ocean.service.library.CategoryService;
import com.ocean.service.library.LibraryService;
import com.ocean.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Project：SchoolManage
 * Package：com.ocean.service.library.impl
 * Author:zy
 * Time:2023/3/3
 */

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryDao categoryDao;


    @Override
    public R save(Category category) {
        if (categoryDao.insert(category) > 0) {
            return R.ok();
        } else {
            return R.fail("插入类别失败");
        }
    }

    @Override
    public R queryPage(int page, int size, String name, String detail) {
        PageHelper.startPage(page, size);
        PageInfo<Category> pageInfo = new PageInfo<Category>(categoryDao.selectAllByCondition(name,detail));
        return R.ok(pageInfo);
    }

    @Override
    public R delete(int id) {
        if(categoryDao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(Category category) {
        return R.ok(categoryDao.update(category));
    }

    @Override
    public R queryAll() {
        return R.ok(categoryDao.selectAll());
    }
}

